package com.hy.controller;

import com.hy.grace.result.GraceJSONResult;
import com.hy.pojo.Candidate;
import com.hy.pojo.bo.CandidateBO;
import com.hy.pojo.bo.InterviewerBO;
import com.hy.pojo.vo.CandidateVO;
import com.hy.service.CandidateService;
import com.hy.utils.PagedGridResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/candidate")
public class CandidateController {

    @Autowired
    private CandidateService candidateService;


    /**
     * 创建或更新候选人信息
     * @param candidateBO
     * @return
     */
    @PostMapping("/createOrUpdate")
    public GraceJSONResult createOrUpdate(@RequestBody CandidateBO candidateBO) {
        candidateService.createOrUpdate(candidateBO);
        return GraceJSONResult.ok();
    }

    /**
     * 获取候选人列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public GraceJSONResult list(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                @RequestParam String realName,
                                @RequestParam String mobile){
        PagedGridResult result = candidateService.queryCandidateList(realName, mobile, page, pageSize);
        return GraceJSONResult.ok(result);
    }


    /**
     * 获取候选人详情
     * @param candidateId
     * @return
     */
    @GetMapping("/detail")
    public GraceJSONResult detail(@RequestParam String candidateId) {
        Candidate detail = candidateService.getDetail(candidateId);
        return GraceJSONResult.ok(detail);
    }

    /**
     * 删除候选人信息
     * @param candidateId
     * @return
     */
    @DeleteMapping("/delete")
    public GraceJSONResult delete(@RequestParam String candidateId) {
        candidateService.deleteById(candidateId);
        return GraceJSONResult.ok();
    }
}
